#ifndef PARTICLE_EFFECT
#define PARTICLE_EFFECT
#include "Common.hlsl"
#include "ComputeBuffs.hlsl"
float line_len;

ByteAddressBuffer Particle_alive_Counter;
StructuredBuffer<uint>alive_index;
AppendStructuredBuffer<uint> line_index;//ready to add

RWStructuredBuffer<uint>line_Counter;
bool Callen(Particle p1,Particle p2)
{
    float3 x=p1.position-p2.position;
    
    float len2=dot(x,x);
    if(len2<line_len*line_len)
    {
        return true;
    }
    return false;
}
[numthreads(THREAD_COUNT, 1, 1)]
void CalLine(uint3 id : SV_DispatchThreadID)
{
    uint count=Particle_alive_Counter.Load(0);
    if(id.x<count)
    {
        bool flag=true;
        int len=0;
        Particle p = particles[id.x];
        //[unroll(88)]
        for(uint i=id.x+1;i<count;i++)
        {
            int index=alive_index[i];
            Particle p1 = particles[index];
            // 
            
            if(Callen(p,p1))
            {
                if(flag)
                {
                    line_index.Append(id.x);
                    flag=false;
                    
                }
                if(len<5)
                {
                    
                    len++;
                    line_Counter.IncrementCounter();
                }
            }
        }
        
        
    }
}
#endif